<?php
/**
 * @category    system
 * @package     logger
 * @subpackage  logger
 * @author      nam nguyen <nam.ngvan@gmail.com>
 * @version     1.0.0
 * @license     $.license
 * this base class is support to log writer.
 *
 */
class Logger
{

    const ERROR = 'ERROR';

    const DEBUG = 'DEBUG';

    const INFO = 'INFO';

    const WARNING = 'WARNING';

    const NOTICE = 'NOTICE';

    /**
     * @var array
     */
    static protected $_inst = array();

    /**
     * logging config name
     * @var string
     */
    protected $_name = NULL;

    /**
     * get log writer
     * get log instance
     * @return Logger
     */
    static public function inst($name = NULL)
    {
        if (NULL == $name)
        {
            $name = 'default';
        }

        if (!isset(self::$_inst[$name]))
        {
            $config = array();
            $class = 'Logger_File';
            self::$_inst[$name] = new $class($name, $config);
        }

        return self::$_inst[$name];
    }

    /**
     * @var array
     */
    protected $_config = array();

    /**
     * constructor
     * @param string $name
     * @param array  $config
     */
    protected function __construct($name, $config)
    {
        $this -> _name = $name;
        $this -> _config = $config;
    }

    /**
     * @param string $name
     * @param mixed $default
     * @return mixed
     */
    public function getConfig($key, $default = null)
    {
        return isset($this -> _config[$key]) ? $this -> _config[$key] : $default;
    }

    /**
     * public function configure
     * @param string/int $level
     * @param string/int $message
     * @return formatted string
     */
    public function format($level, $message)
    {
        return PHP_EOL . date('Y-m-d H:i:s') . ':' . $level . PHP_EOL . $message . PHP_EOL;
    }

}
